<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * CMS
 */
namespace Mall\Controller;
use Common\Controller\AdminController;
Vendor('Qiniusdk.autoload'); //七牛入口文件引入 
use Qiniu\Auth; 
use Qiniu\Storage\UploadManager;
use Think\Upload;
use Qiniu\Processing\PersistentFop;
/**
 * 菜单
 */
class ClassifyController extends AdminController{
	
	#专辑试听转码
	public function type_zhuanma_shiting($type,$result,$url){
		$m_mall_content_music = M("mall_content_music");
		#$type = 4;
		$this->upload_video_shiting($url);
		$music_add['type'] = $type;
		$music_add['form_id'] = $result;
		$name_array = explode(".",$url);
		$music_add['url'] = "http://p7j34hu3o.bkt.clouddn.com/".$name_array[0]."_s.mp3";
		$m_mall_content_music->add($music_add);
	}
	
	
	public function upload_video_shiting($key) {
		$accessKey = "8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a";
		$secretKey = "FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE";
		$bucket = "music";
		$auth = new Auth($accessKey, $secretKey);
		//要转码的文件所在的空间和文件名。
		#$key = '1527143791383.flac';
		//转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline   1527231255422.flac
		$pipeline = 'music_zhuanma';
		$force = false;
		//转码完成后通知到你的业务服务器。
		$notifyUrl = 'http://music.liurizhao.zaiyoudao.com/music/port/qiniu.php';
		$config = new \Qiniu\Config();
		#dump($err);die;
		//$config->useHTTPS=true;
		$pfop = new PersistentFop($auth, $config);
		//要进行转码的转码操作。 http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
		$name_array = explode(".",$key);
		
		$fops = "avthumb/mp3/ss/0/t/30|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":".$name_array[0]."_s.mp3");
		list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force);
		
		#暂时不用
		/* echo "\n====> pfop avthumb result: \n";
		if ($err != null) {
			var_dump($err);
		} else {
			echo "PersistentFop Id: $id\n";
		}
		//查询转码的进度和状态
		list($ret, $err) = $pfop->status($id);
		echo "\n====> pfop avthumb status: \n";
		if ($err != null) {
			var_dump($err);
		} else {
			var_dump($ret);
		} */
	}
	
	
	/**
	 *  专辑管理
	 */
    public function All_album(){
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =array('like',"%$uid%");
		}
		$this->assign('uid',$uid);
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//判断是否搜索状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
			$this->assign('status',$status);
		}else{
			$map['status'] = array('in','1,2,3,4,5');
		}
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$map['type'] = get_mall_model_conf('MALL_ALBUM');
		$list = $m_mall_content->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		#dump($map);die;
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出 
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['channel'] = $fdata['name'];
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['n_img'] = $udata['img'];
		}
		//dump($list);die;
		//赋值
		$this->assign('list',$list);
		
		$status_list = getstatus();
		$this->assign('status_list',$status_list);
		$this->display();
	}
	
	/**
	 *  专辑管理
	 */
    public function tui_album(){
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =array('like',"%$uid%");
		}
		$this->assign('uid',$uid);
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$map['type'] = get_mall_model_conf('MALL_ALBUM');
		$map['status'] = 1;
		$map['recommended'] = 1;
		$list = $m_mall_content->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		#dump($map);die;
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出 
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['channel'] = $fdata['name'];
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['n_img'] = $udata['img'];
		}
		#dump($list);die;
		//赋值
		$this->assign('list',$list);
		$this->display();
	}
	/**
	 *  专辑管理
	 */
    public function no_album(){
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		
		//用户UID
		$uid = I('param.uid')?I('param.uid'):'';

		if($uid!=0){
			
			$map['uid'] =array('like',"%$uid%");
		}
		$this->assign('uid',$uid);
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$map['type'] = get_mall_model_conf('MALL_ALBUM');
		$map['status'] = 3;
		$list = $m_mall_content->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		#dump($map);die;
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出 
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			$umap['id'] = $list[$i]['uid'];
			$udata = $m_common_user->where($umap)->find();
			$list[$i]['channel'] = $fdata['name'];
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['n_img'] = $udata['img'];
		}
		//dump($list);die;
		//赋值
		$this->assign('list',$list);
		$this->display();
	}
	
	/* 新增专辑 */
	 public function u_ajax(){
		
		 $this->display();
	 }
	
	public function ajax_shangchuan(){
		
		#七牛云
		 Vendor('Qny.autoload');
        // 用于签名的公钥和私钥
        $accessKey = '8sc_uncdqBnQUYyWViRALobZH33YO_lZKD65Y04a';
        $secretKey = 'FczTgs6OmHBb7jke7pExGeujvxIHXO0trUCIbmBE';
        // 初始化签权对象
        $auth = new Auth($accessKey, $secretKey);
        // 空间名  https://developer.qiniu.io/kodo/manual/concepts
//        p78151fwl.bkt.clouddn.com
        $bucket = 'music';
        // 生成上传Token
        $token = $auth->uploadToken($bucket);
        // 构建 UploadManager 对象
        $uploadMgr = new UploadManager();
		
		 $url = 'http://p7j34hu3o.bkt.clouddn.com/';
		
		
		 header('content-type:text/html;charset:utf-8');
		 $m_common_upload_type = M("common_upload_type");
		 $m_common_upload = M("common_upload");
		 
		 $userid = getUID()?getUID():0;
		$dir_base = './upload/'.$userid.'/'.date('Y',time()).'/'.date('m',time()).'/'.date('d',time()).'/';
		$dir_bases = '/upload/'.$userid.'/'.date('Y',time()).'/'.date('m',time()).'/'.date('d',time()).'/';
		//$dir_base = "./files/";     //文件上传根目录
		//没有成功上传文件，报错并退出。
		$output = "<textarea>";
		$index = 0;        //$_FILES 以文件name为数组下标，不适用foreach($_FILES as $index=>$file)
		
		
		foreach($_FILES as $file){
			$upload_file_name = 'upload_file' . $index;        //对应index.html FomData中的文件命名
			
			$filename_array = explode(".",$_FILES[$upload_file_name]['name']);
			$filename = uniqid($index).'.'.$filename_array[1];
			//filename
			$filename_save = $_FILES[$upload_file_name]['name'];
			
			
			$gb_filename = iconv('utf-8','gb2312',$filename);    //名字转换成gb2312处理
			//文件不存在才上传
			/* var_dump($dir_bases);
			var_dump($gb_filename);
			var_dump(file_exists($dir_bases.$gb_filename));die; */
			if(!file_exists($dir_base.$gb_filename)) {
				
				if (! file_exists ( $dir_base )) {
					mkdir ( "$dir_base", 7777, true );
				}
				$isMoved = false;  //默认上传失败
				$MAXIMUM_FILESIZE = 80 * 1024 * 1024;     //文件大小限制    1M = 1 * 1024 * 1024 B;
				$rEFileTypes = "/^\.(jpg|jpeg|gif|png|mp3|lrc|gif|flac){1}$/i"; 
				if ($_FILES[$upload_file_name]['size'] <= $MAXIMUM_FILESIZE && 
					preg_match($rEFileTypes, strrchr($gb_filename, '.'))) {
					list($ret, $err) = $uploadMgr->putFile($token,$gb_filename,$_FILES[$upload_file_name]['tmp_name']);
					$true_url=$url.$ret['key'];
					
					#$isMoved = @move_uploaded_file ( $_FILES[$upload_file_name]['tmp_name'], $dir_base.$gb_filename);        //本地上传文件
				}
			}else{
				$isMoved = true;    //已存在文件设置为上传成功
			}
			
			  if ($err !== null) {//上传出错
					//上传失败则把error.jpg传回给前端
					//$output .= "<img src='{$dir_base}error.jpg' title='{$filename}' alt='{$filename}'/>";
					//$img_src[] = $dir_bases.$dir_base.'error.jpg';
				}else {
					//输出图片文件<img>标签
					//注：在一些系统src可能需要urlencode处理，发现图片无法显示，
					//请尝试 urlencode($gb_filename) 或 urlencode($filename)，不行请查看HTML中显示的src并酌情解决。
					$output .= "<img src='{$dir_bases}{$filename}' title='{$filename}' alt='{$filename}'/>";
					#$img_src[$index]['url'] = $dir_bases.$filename;
					$img_src[$index]['url'] = $true_url;
					$img_src[$index]['size'] = $_FILES[$upload_file_name]['size'];
					
					#上传类型
					$cutmap['title'] = $filename_array[1];
					$cutdata = $m_common_upload_type->where($cutmap)->find();
					if($cutdata){
						$cuttype = $cutdata['id'];
					}else{
						$cutsdata['title'] = "$filename_array[1]";
						$cutsdata['status'] = 1;
						$cuttype = $m_common_upload_type->add($cutsdata);
					}
					
					$cudata =array(
						'status'=>1,
						#'url'=> $dir_bases.$filename,
						'url'=> $true_url,
						'title'=>$gb_filename,
						'original'=>$filename_save,
						'type'=>$cuttype,
						'size'=>$_FILES[$upload_file_name]['size'],
						'time'=>time(),
						'uid'=>$userid,
						
					);
					//var_dump($cudata);exit;
					$m_common_upload->add($cudata);
					
					
					
					
				}
				$index++;
		}
		#echo $output."</textarea>";
		$this->ajaxReturn($img_src);
	}
	
	/* 新增专辑 */
	 public function create_albums(){
		 
		include_once 'upload.func.php';
		$m_mall_content = M("mall_content");
		 
		 if(IS_POST){
			 /* dump(I());die; */
			$style = I("param.style");
			$data['langue'] = I("param.langue");         //语言
			$data['banner_img'] = I("param.banner_img");         //语言
			$data['style'] = implode(',',I("param.style"));             //流派风格
			$data['name'] = I("param.name");             //专辑名称
			$data['isrc'] = I("param.isrc");          //唯一标示
			$data['lyrics'] = I("param.lyrics");          //作词
			$data['compose'] = I("param.compose");        //作曲
			$data['arranged'] = I("param.arranged");      //编曲
			$data['record'] = I("param.record");           //录音
			$data['mixing'] = I("param.mixing");           //混音
			$data['singer'] = I("param.singer");           //演唱者
			$data['producer'] = I("param.producer");       //制作人
			$data['producers'] = I("param.producers");       //出品方
			$data['money'] = I("param.money");       //出售单价
			$data['inventory'] = I("param.inventory");       //发行量
			$data['release_time'] = strtotime(I("param.release_time"));       //发行时间
			$data['img'] = I("param.img");       //封面图
			$data['bottom_img'] = I("param.bottom_img");       //封底图
			$data['color_img'] = I("param.color_img");       //宣传彩页图
			//$data['foil_img'] = I("param.foil_img");       //歌词本底衬页图
			$data['intro'] = I("param.intro");       //专辑介绍
			$data['time'] = time();
			$data['type'] = get_mall_model_conf('MALL_ALBUM');
			$data['ip'] = get_client_ip();
			$data['status'] = 2;
			$data['value'] = I('param.value')?I('param.value'):'';
			$data['uid'] = getUID();
			
			$result = $m_mall_content->add($data);
			#添加歌曲
			if($result){
				#添加流派风格
				add_style(2,$result,$style); 
				
				
				#歌曲文件 music_song
				$music_song = $_FILES['music_song'];
				foreach($music_song as $i=>$v){
					foreach($music_song[$i] as $ii=>$vv){
						$music_song_list[$ii][$i] = $music_song[$i][$ii];
					}
				}
				
				#歌曲名称 music_name  
				
				$music_name = I("param.music_name");
				
				#歌词 music_lyrics
				$music_lyrics = $_FILES['music_lyrics'];
				foreach($music_lyrics as $i=>$v){
					foreach($music_lyrics[$i] as $ii=>$vv){
						$music_lyrics_list[$ii][$i] = $music_lyrics[$i][$ii];
					}
				}
				#歌词本底衬页图  foil_img
				$foil_img = $_FILES['foil_img'];
				
				foreach($foil_img as $i=>$v){
					foreach($foil_img[$i] as $ii=>$vv){
						$foil_img_list[$ii][$i] = $foil_img[$i][$ii];
					}
				}
				
				foreach($music_song_list as $fileInfo) {  
					$res = uploadFile($fileInfo); 
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$gequ_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$music_song_list[$i]['name'],$uploadFiles[$i],$music_song_list[$i]['size']);
				}
				$uploadFiles = array();
				
				#歌词上传
				foreach($music_lyrics_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$geci_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$music_lyrics_list[$i]['name'],$uploadFiles[$i],$music_lyrics_list[$i]['size']);
				}
				
				#歌词本底衬页图  foil_img
				$uploadFiles = array();
				foreach($foil_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$gecichenye_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$foil_img_list[$i]['name'],$uploadFiles[$i],$foil_img_list[$i]['size']);
				}
				#获取对应歌曲个数
				$music_img_count = I('param.music_img_count');
				
				#添加该专辑下的歌曲
				$cc_count = 0;
				
				foreach($gequ_array as $gi=>$gv){
					$song_map['mp3'] = $gequ_array[$gi];
					$song_map['name'] = $music_name[$gi];
					if($geci_array[$gi]){
						$song_map['value'] = $geci_array[$gi];
					}
					$song_map['form_id'] = $result;
					$song_map['uid'] = getUID();
					$song_map['type'] = get_mall_model_conf('MALL_SONG');  //表示专辑下的歌曲
					$song_map['ip'] = get_client_ip();
					$song_map['status'] = 1;
					$geci_result = $m_mall_content->add($song_map);
				
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(2,$geci_result,trim($uploadFiles[$cc_count],'.'));
						$cc_count ++;
					}
						
				}
			}
			
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
				$this->success('新增成功', U('Mall/Classify/Album'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
				$this->error('新增失败');
			}
		 }else{
			 #查询语言
			$langeue_list = getlangeues();
			#查询流派风格
			$type_list = gettypes();
			
			$this->assign("langeue_list",$langeue_list);
			$this->assign("type_list",$type_list);
			$this->assign("time",time());
			$this->display();			
		 }
	 }
	 
	/* 新增专辑 */
	 public function create_album(){
		include_once 'upload.func.php';
		$m_mall_content = M("mall_content");
		 if(IS_POST){
			$style = I("param.style");
			$style_array = implode(',',$style);             //流派风格
			$data['langue'] = I("param.langue");         //语言
			if($style_array){
				$data['style'] = $style_array;
			}
			$data['singer'] = I("param.singer");           //歌手
			$data['banner_img'] = I("param.banner_img");           //歌手
			$data['isrc'] = I("param.isrc");          //唯一标示
			$data['name'] = I("param.name");               //专辑名称
			$data['money'] = I("param.money");       //出售单价
			$data['inventory'] = I("param.inventory");       //发行量
			$data['release_time'] = strtotime(I("param.release_time"));       //发行时间
			$data['img'] = I("param.img");       //封面图
			$data['bottom_img'] = I("param.bottom_img");       //封底图
			$data['intro'] = I("param.intro");       //专辑介绍
			$data['time'] = time();
			$data['type'] = get_mall_model_conf('MALL_ALBUM');
			$data['ip'] = get_client_ip();
			$data['status'] = 2;
			$data['value'] = I('param.value')?I('param.value'):'';
			$data['uid'] = getUID();
			$result = $m_mall_content->add($data);
			#添加歌曲
			if($result){
				
				#添加流派风格
				add_style(2,$result,$style); 
				#获取对应歌曲个数
				$music_img_count = I('param.music_img_count');
				$xuanchuan_img_count = I('param.xuanchuan_img_count');
				$mp3_list = I('param.mp3');    #歌曲文件
				
				$music_name = I("param.music_name");   #歌曲名称 
				$langues = I('param.langues');    #语言
				$producers = I("param.producers");    #出品方 
				$producer = I("param.producer");    #制作人 
				$singers = I("param.singers");    #演唱者 
				$mixings = I("param.mixings");    #混音 
				$records = I("param.records");    #录音 
				$composes = I("param.composes");    #作曲 
				$lyrics = I("param.lyrics");    #作曲
				
				# 内页 color_img
				$color_img = $_FILES['color_img'];
				foreach($color_img as $i=>$v){
					foreach($color_img[$i] as $ii=>$vv){
						$color_img_list[$ii][$i] = $color_img[$i][$ii];
					}
				}
				foreach($color_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					
					if(isset($res['dest'])) {  
						$uploadFiless[] = $res['dest'];  
					}  
				}
				$uploadFiless=array_filter($uploadFiless);
				foreach($uploadFiless as $i=>$v){
					$img_name_list = explode("/",$uploadFiless[$i]);
					$count = count($img_name_list);
					$str_strs = substr($uploadFiless[$i],1);
					$neiye_array[] = $str_strs;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$color_img_list[$i]['name'],$uploadFiless[$i],$color_img_list[$i]['size']);
					mall_img(4,$result,trim($uploadFiless[$i],'.'));
				}
				
				#歌词 music_lyrics
				$music_lyrics = $_FILES['music_lyrics'];
				foreach($music_lyrics as $i=>$v){
					foreach($music_lyrics[$i] as $ii=>$vv){
						$music_lyrics_list[$ii][$i] = $music_lyrics[$i][$ii];
					}
				}
			
				#歌词本底衬页图  foil_img
				$foil_img = $_FILES['foil_img'];
				
				foreach($foil_img as $i=>$v){
					foreach($foil_img[$i] as $ii=>$vv){
						$foil_img_list[$ii][$i] = $foil_img[$i][$ii];
					}
				}
				
				$uploadFiles = array();
				
				#歌词上传
				foreach($music_lyrics_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$geci_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$music_lyrics_list[$i]['name'],$uploadFiles[$i],$music_lyrics_list[$i]['size']);
				}
				
				#歌词本底衬页图  foil_img
				$uploadFiles = array();
				foreach($foil_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$gecichenye_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$foil_img_list[$i]['name'],$uploadFiles[$i],$foil_img_list[$i]['size']);
				}
				
				#宣传图  xuanchuan_img
				$xuanchuan_img = $_FILES['xuanchuan_img'];
				foreach($xuanchuan_img as $i=>$v){
					foreach($xuanchuan_img[$i] as $ii=>$vv){
						$xuanchuan_img_list[$ii][$i] = $xuanchuan_img[$i][$ii];
					}
				}
				
				$uploadFiless = array();
				foreach($xuanchuan_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiless[] = $res['dest'];  
					}  
				}
				$uploadFiless=array_filter($uploadFiless);
				foreach($uploadFiless as $i=>$v){
					$img_sname_list = explode("/",$uploadFiless[$i]);
					$count = count($img_sname_list);
					$str_strs = substr($uploadFiless[$i],1);
					$gecichenye_array[] = $str_strs;
					#源文件与现文件记录
					upload_file_name($img_sname_list[$count - 1],$xuanchuan_img_list[$i]['name'],$uploadFiless[$i],$xuanchuan_img_list[$i]['size']);
				}
				#添加该专辑下的歌曲
				$cc_count = 0;
				$cc_counts = 0;
				
				foreach($mp3_list as $gi=>$gv){
					$song_map['mp3'] = $mp3_list[$gi];
					$song_map['name'] = $music_name[$gi];
					$song_map['langue'] = $langues[$gi];
					$song_map['producers'] = $producers[$gi];
					$song_map['producer'] = $producer[$gi];
					$song_map['singer'] = $singers[$gi];
					$song_map['mixing'] = $mixings[$gi];
					$song_map['record'] = $records[$gi];
					$song_map['compose'] = $composes[$gi];
					$song_map['lyrics'] = $lyrics[$gi];
					
					if($geci_array[$gi]){
						$song_map['value'] = $geci_array[$gi];
					}
					
					$song_map['form_id'] = $result;
					$song_map['uid'] = getUID();
					$song_map['type'] = get_mall_model_conf('MALL_SONG');  //表示专辑下的歌曲
					$song_map['ip'] = get_client_ip();
					$song_map['status'] = 1;
					$geci_result = $m_mall_content->add($song_map);
					#添加试听歌曲
					$shiting_array = explode(".com/",$mp3_list[$gi]);
					$this->type_zhuanma_shiting(5,$geci_result,$shiting_array[1]);
					
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(2,$geci_result,trim($uploadFiles[$cc_count],'.'));
						$cc_count ++;
					}
					
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(3,$geci_result,trim($uploadFiless[$cc_counts],'.'));
						$cc_counts ++;
					}
						
				}
			}
			
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
				$this->success('新增成功', U('Mall/Classify/Album'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置   
				$this->error('新增失败');
			}
		 }else{
			 #查询语言
			$langeue_list = getlangeues();
			#查询流派风格
			$type_list = gettypes();
			foreach($type_list as $i=>$v){
				$type_str .= "<option value ='".$type_list[$i]['id']."'>".$type_list[$i]['name']."</option>";
			}
			foreach($langeue_list as $i=>$v){
				$langeue_str .= "<option value ='".$langeue_list[$i]['id']."'>".$langeue_list[$i]['name']."</option>";
			}
			#dump($langeue_str);die; 
			$this->assign("type_str",$type_str);
			$this->assign("langeue_str",$langeue_str);
			$this->assign("langeue_list",$langeue_list);
			$this->assign("type_list",$type_list);
			$this->assign("time",time());
			$this->display();			
		 }
		 
		
	 }
	/* 新增专辑 */
	 public function create_album_user(){
		include_once 'upload.func.php';
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		 if(IS_POST){
			$museic_user_id = I("param.museic_user_id");
			$style = I("param.style");
			$style_array = implode(',',$style);             //流派风格
			$data['langue'] = I("param.langue");         //语言
			if($style_array){
				$data['style'] = $style_array;
			}
			$data['banner_img'] = I("param.banner_img");           //歌手
			$data['isrc'] = I("param.isrc");           //唯一标示
			
			$data['singer'] = I("param.singer");           //歌手
			$data['name'] = I("param.name");               //专辑名称
			$data['money'] = I("param.money");       //出售单价
			$data['inventory'] = I("param.inventory");       //发行量
			$data['release_time'] = strtotime(I("param.release_time"));       //发行时间
			$data['img'] = I("param.img");       //封面图
			$data['bottom_img'] = I("param.bottom_img");       //封底图
			$data['intro'] = I("param.intro");       //专辑介绍
			$data['time'] = time();
			$data['type'] = get_mall_model_conf('MALL_ALBUM');
			$data['ip'] = get_client_ip();
			$data['status'] = 2;
			$data['value'] = I('param.value')?I('param.value'):'';
			$data['uid'] = $museic_user_id;
			$result = $m_mall_content->add($data);
			#添加歌曲
			if($result){
				#添加流派风格
				add_style(2,$result,$style); 
				#获取对应歌曲个数
				$music_img_count = I('param.music_img_count');
				$xuanchuan_img_count = I('param.xuanchuan_img_count');
				$mp3_list = I('param.mp3');    #歌曲文件
				
				$music_name = I("param.music_name");   #歌曲名称 
				$langues = I('param.langues');    #语言
				$producers = I("param.producers");    #出品方 
				$producer = I("param.producer");    #制作人 
				$singers = I("param.singers");    #演唱者 
				$mixings = I("param.mixings");    #混音 
				$records = I("param.records");    #录音 
				$composes = I("param.composes");    #作曲 
				$lyrics = I("param.lyrics");    #作曲
				
				# 内页 color_img
				$color_img = $_FILES['color_img'];
				foreach($color_img as $i=>$v){
					foreach($color_img[$i] as $ii=>$vv){
						$color_img_list[$ii][$i] = $color_img[$i][$ii];
					}
				}
				foreach($color_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					
					if(isset($res['dest'])) {  
						$uploadFiless[] = $res['dest'];  
					}  
				}
				$uploadFiless=array_filter($uploadFiless);
				foreach($uploadFiless as $i=>$v){
					$img_name_list = explode("/",$uploadFiless[$i]);
					$count = count($img_name_list);
					$str_strs = substr($uploadFiless[$i],1);
					$neiye_array[] = $str_strs;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$color_img_list[$i]['name'],$uploadFiless[$i],$color_img_list[$i]['size']);
					mall_img(4,$result,trim($uploadFiless[$i],'.'));
				}
				
				#歌词 music_lyrics
				$music_lyrics = $_FILES['music_lyrics'];
				foreach($music_lyrics as $i=>$v){
					foreach($music_lyrics[$i] as $ii=>$vv){
						$music_lyrics_list[$ii][$i] = $music_lyrics[$i][$ii];
					}
				}
			
				#歌词本底衬页图  foil_img
				$foil_img = $_FILES['foil_img'];
				
				foreach($foil_img as $i=>$v){
					foreach($foil_img[$i] as $ii=>$vv){
						$foil_img_list[$ii][$i] = $foil_img[$i][$ii];
					}
				}
				
				$uploadFiles = array();
				
				#歌词上传
				foreach($music_lyrics_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$geci_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$music_lyrics_list[$i]['name'],$uploadFiles[$i],$music_lyrics_list[$i]['size']);
				}
				
				#歌词本底衬页图  foil_img
				$uploadFiles = array();
				foreach($foil_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$gecichenye_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$foil_img_list[$i]['name'],$uploadFiles[$i],$foil_img_list[$i]['size']);
				}
				
				#宣传图  xuanchuan_img
				$xuanchuan_img = $_FILES['xuanchuan_img'];
				foreach($xuanchuan_img as $i=>$v){
					foreach($xuanchuan_img[$i] as $ii=>$vv){
						$xuanchuan_img_list[$ii][$i] = $xuanchuan_img[$i][$ii];
					}
				}
				
				$uploadFiless = array();
				foreach($xuanchuan_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiless[] = $res['dest'];  
					}  
				}
				$uploadFiless=array_filter($uploadFiless);
				foreach($uploadFiless as $i=>$v){
					$img_sname_list = explode("/",$uploadFiless[$i]);
					$count = count($img_sname_list);
					$str_strs = substr($uploadFiless[$i],1);
					$gecichenye_array[] = $str_strs;
					#源文件与现文件记录
					upload_file_name($img_sname_list[$count - 1],$xuanchuan_img_list[$i]['name'],$uploadFiless[$i],$xuanchuan_img_list[$i]['size']);
				}
				#添加该专辑下的歌曲
				$cc_count = 0;
				$cc_counts = 0;
				
				foreach($mp3_list as $gi=>$gv){
					$song_map['mp3'] = $mp3_list[$gi];
					$song_map['name'] = $music_name[$gi];
					$song_map['langue'] = $langues[$gi];
					$song_map['producers'] = $producers[$gi];
					$song_map['producer'] = $producer[$gi];
					$song_map['singer'] = $singers[$gi];
					$song_map['mixing'] = $mixings[$gi];
					$song_map['record'] = $records[$gi];
					$song_map['compose'] = $composes[$gi];
					$song_map['lyrics'] = $lyrics[$gi];
					
					if($geci_array[$gi]){
						$song_map['value'] = $geci_array[$gi];
					}
					$song_map['form_id'] = $result;
					$song_map['uid'] = $museic_user_id;
					$song_map['type'] = get_mall_model_conf('MALL_SONG');  //表示专辑下的歌曲
					$song_map['ip'] = get_client_ip();
					$song_map['status'] = 1;
					$geci_result = $m_mall_content->add($song_map);
					#添加试听歌曲
					$shiting_array = explode(".com/",$mp3_list[$gi]);
					$this->type_zhuanma_shiting(5,$geci_result,$shiting_array[1]);
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(2,$geci_result,trim($uploadFiles[$cc_count],'.'));
						$cc_count ++;
					}
					
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(3,$geci_result,trim($uploadFiless[$cc_counts],'.'));
						$cc_counts ++;
					}
						
				}
			}
			
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
				$this->success('新增成功', U('Mall/Classify/all_album'));
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置   
				$this->error('新增失败');
			}
		 }else{
			 
			 #查询语言
			$langeue_list = getlangeues();
			#查询流派风格
			$type_list = gettypes();
			foreach($type_list as $i=>$v){
				$type_str .= "<option value ='".$type_list[$i]['id']."'>".$type_list[$i]['name']."</option>";
			}
			foreach($langeue_list as $i=>$v){
				$langeue_str .= "<option value ='".$langeue_list[$i]['id']."'>".$langeue_list[$i]['name']."</option>";
			}
			#查询所有音乐人
			$music_u_map['group_id'] = 9;
			$music_u_map['status'] = 1;
			$music_u_list = $m_common_user->where($music_u_map)->where($music_u_map)->field("id,nickname")->select();
			
			
			#dump($langeue_str);die; 
			$this->assign("music_u_list",$music_u_list);
			$this->assign("type_str",$type_str);
			$this->assign("langeue_str",$langeue_str);
			$this->assign("langeue_list",$langeue_list);
			$this->assign("type_list",$type_list);
			$this->assign("time",time());
			$this->display();			
		 }
		 
		
	 }
	
	/* 编辑专辑 */
	 public function Edit_album(){
		
		$m_mall_content = M('mall_content');
		$m_common_upload = M('common_upload');
		include_once 'upload.func.php';
		
		//判断是否是ajax请求
		if(IS_POST){
			
			# 编辑专辑相应内容
			
			$style = I("param.style");
			$style_array = implode(',',$style);             //流派风格
			$data['langue'] = I("param.langue");         //语言
			if($style_array){
				$data['style'] = $style_array;
			}
			$data['singer'] = I("param.singer");           //歌手
			$data['banner_img'] = I("param.banner_img");           //歌手
			$data['isrc'] = I("param.isrc");          //唯一标示
			$data['name'] = I("param.name");               //专辑名称
			$data['money'] = I("param.money");       //出售单价
			$data['inventory'] = I("param.inventory");       //发行量
			$data['release_time'] = strtotime(I("param.release_time"));       //发行时间
			$data['img'] = I("param.img");       //封面图
			$data['bottom_img'] = I("param.bottom_img");       //封底图
			$data['intro'] = I("param.intro");       //专辑介绍
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$edit_id_map['id'] = I('param.form_id');
			$edit_id_map['uid'] = getUID();
			$result = $m_mall_content->where($edit_id_map)->save($data);
				#编辑专辑下歌曲
				$edit_id = I('param.edit_id');    #歌曲id
				$edit_name = I('param.edit_name');    #歌曲名称
				$edit_langues = I('param.edit_langues');    #歌曲语言
				$edit_lyrics = I('param.edit_lyrics');    #作词
				$edit_composes = I('param.edit_composes');    #作曲
				$edit_records = I('param.edit_records');    #录音
				$edit_mixings = I('param.edit_mixings');    #混音
				$edit_singers = I('param.edit_singers');    #演唱者
				$edit_producer = I('param.edit_producer');    #制作人
				$edit_producers = I('param.edit_producers');    #出品方
				$edit_music_lyrics = I('param.edit_music_lyrics');    #歌词
				
				
				foreach($edit_id as $i=>$v){
					$edit_song_map['id'] = $edit_id[$i];
					$edit_song_data['name'] = $edit_name[$i];
					$edit_song_data['langue'] = $edit_langues[$i];
					$edit_song_data['lyrics'] = $edit_lyrics[$i];
					$edit_song_data['compose'] = $edit_composes[$i];
					$edit_song_data['record'] = $edit_records[$i];
					$edit_song_data['mixing'] = $edit_records[$i];
					$edit_song_data['singer'] = $edit_singers[$i];
					$edit_song_data['producer'] = $edit_producer[$i];
					$edit_song_data['producers'] = $edit_producers[$i];
					$edit_song_data['value'] = $edit_music_lyrics[$i];
					#歌词  file上传
					$m_mall_content->where($edit_song_map)->save($edit_song_data);
				}
				
				
				
				#新增专辑下歌曲
				
				#添加流派风格
				add_style(2,$edit_id_map['id'],$style); 
				#获取对应歌曲个数
				$music_img_count = I('param.music_img_count');
				$xuanchuan_img_count = I('param.xuanchuan_img_count');
				$mp3_list = I('param.mp3');    #歌曲文件
				$music_name = I("param.music_name");   #歌曲名称 
				$langues = I('param.langues');    #语言
				$producers = I("param.producers");    #出品方 
				$producer = I("param.producer");    #制作人 
				$singers = I("param.singers");    #演唱者 
				$mixings = I("param.mixings");    #混音 
				$records = I("param.records");    #录音 
				$composes = I("param.composes");    #作曲 
				$lyrics = I("param.lyrics");    #作曲
				
				#歌词 music_lyrics
				$music_lyrics = $_FILES['music_lyrics'];
				foreach($music_lyrics as $i=>$v){
					foreach($music_lyrics[$i] as $ii=>$vv){
						$music_lyrics_list[$ii][$i] = $music_lyrics[$i][$ii];
					}
				}
			
				#歌词本底衬页图  foil_img
				$foil_img = $_FILES['foil_img'];
				
				foreach($foil_img as $i=>$v){
					foreach($foil_img[$i] as $ii=>$vv){
						$foil_img_list[$ii][$i] = $foil_img[$i][$ii];
					}
				}
				
				$uploadFiles = array();
				
				#歌词上传
				foreach($music_lyrics_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$geci_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$music_lyrics_list[$i]['name'],$uploadFiles[$i],$music_lyrics_list[$i]['size']);
				}
				
				#歌词本底衬页图  foil_img
				$uploadFiles = array();
				foreach($foil_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$gecichenye_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$foil_img_list[$i]['name'],$uploadFiles[$i],$foil_img_list[$i]['size']);
				}
				
				#宣传图  xuanchuan_img
				$xuanchuan_img = $_FILES['xuanchuan_img'];
				foreach($xuanchuan_img as $i=>$v){
					foreach($xuanchuan_img[$i] as $ii=>$vv){
						$xuanchuan_img_list[$ii][$i] = $xuanchuan_img[$i][$ii];
					}
				}
				
				$uploadFiless = array();
				foreach($xuanchuan_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiless[] = $res['dest'];  
					}  
				}
				$uploadFiless=array_filter($uploadFiless);
				foreach($uploadFiless as $i=>$v){
					$img_sname_list = explode("/",$uploadFiless[$i]);
					$count = count($img_sname_list);
					$str_strs = substr($uploadFiless[$i],1);
					$gecichenye_array[] = $str_strs;
					#源文件与现文件记录
					upload_file_name($img_sname_list[$count - 1],$xuanchuan_img_list[$i]['name'],$uploadFiless[$i],$xuanchuan_img_list[$i]['size']);
				}
				#添加该专辑下的歌曲
				$cc_count = 0;
				$cc_counts = 0;
				
				foreach($mp3_list as $gi=>$gv){
					$song_map['mp3'] = $mp3_list[$gi];
					$song_map['name'] = $music_name[$gi];
					$song_map['langue'] = $langues[$gi];
					$song_map['producers'] = $producers[$gi];
					$song_map['producer'] = $producer[$gi];
					$song_map['singer'] = $singers[$gi];
					$song_map['mixing'] = $mixings[$gi];
					$song_map['record'] = $records[$gi];
					$song_map['compose'] = $composes[$gi];
					$song_map['lyrics'] = $lyrics[$gi];
					
					if($geci_array[$gi]){
						$song_map['value'] = $geci_array[$gi];
					}
					$song_map['form_id'] = $edit_id_map['id'];
					$song_map['uid'] = getUID();
					$song_map['type'] = get_mall_model_conf('MALL_SONG');  //表示专辑下的歌曲
					$song_map['ip'] = get_client_ip();
					$song_map['status'] = 1;
					$geci_result = $m_mall_content->add($song_map);
					
					#添加试听歌曲
					$shiting_array = explode(".com/",$mp3_list[$gi]);
					$this->type_zhuanma_shiting(5,$geci_result,$shiting_array[1]);
				
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(2,$geci_result,trim($uploadFiles[$cc_count],'.'));
						$cc_count ++;
					}
					
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(3,$geci_result,trim($uploadFiless[$cc_counts],'.'));
						$cc_counts ++;
					}
						
				}
			
			
			if($cc_count >0 or $result>0){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
			
				$this->success('编辑成功', U('Mall/Classify/Album'));
			
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
			
				$this->error('编辑失败');
			
			}
		
		}else{
			 #查询语言
			$langeue_list = getlangeues();
			#查询流派风格
			$style_list = gettypes();
			
			$map['id'] = I('param.id');
			$map['type'] = get_mall_model_conf('MALL_ALBUM');
			$map['status'] = array('in','2,4');
			$map['uid'] = getUID();
			$data = $m_mall_content->where($map)->find();
			
			#查询专辑下歌曲
			$f_map['form_id'] = $data['id'];
			$f_map['type'] = 17;    //专辑下歌曲
			$f_map['status'] = 1;  
			$f_list = $m_mall_content->where($f_map)->select();
			#查看歌曲名称
			foreach($f_list as $i=>$v){
				$url = $f_list[$i]['mp3'];
				$url_map['url'] = array("like","%$url%");
				$url_map['status'] = 1;
				$url_data = $m_common_upload->where($url_map)->find();
				$f_list[$i]['song_name'] = $url_data['original'];
				$f_list[$i]['song_size'] = getFilesize($url_data['size']);
				
				$value = $f_list[$i]['value'];
				$url_map['url'] = array("like","%$value%");
				$url_map['status'] = 1;
				$url_data = $m_common_upload->where($url_map)->find();
				$f_list[$i]['value_name'] = $url_data['original'];
				
				foreach($langeue_list as $ii=>$vv){
					if($langeue_list[$ii]['id'] == $f_list[$i]['langue']){
						$langeue_str[$i] .=  "<option selected='selected' value ='".$langeue_list[$ii]['id']."'>".$langeue_list[$ii]['name']."</option>";
					}else{
						$langeue_str[$i] .=  "<option value ='".$langeue_list[$ii]['id']."'>".$langeue_list[$ii]['name']."</option>";
					}
				}
				
				
				
				
			}
			foreach($langeue_list as $i=>$v){
					$langeue_strs .= "<option value ='".$langeue_list[$i]['id']."'>".$langeue_list[$i]['name']."</option>";
				}
			#dump($langeue_str);die;
			$style_list = if_style($style_list,$data['style']);
			$this->assign("langeue_list",$langeue_list);
			$this->assign("langeue_str",$langeue_str);
			$this->assign("langeue_strs",$langeue_strs);
			$this->assign('data',$data);
			$this->assign('f_list',$f_list);
			$this->assign('style_list',$style_list);
			$this->display();
		}
		 
	 }
	
	/* 管理员编辑专辑 */
	 public function Edit_all_album(){
		$m_mall_content = M('mall_content');
		$m_common_upload = M('common_upload');
		include_once 'upload.func.php';
		
		//判断是否是ajax请求
		if(IS_POST){
			
			# 编辑专辑相应内容
			
			$style = I("param.style");
			$style_array = implode(',',$style);             //流派风格
			$data['langue'] = I("param.langue");         //语言
			if($style_array){
				$data['style'] = $style_array;
			}
			$data['isrc'] = I("param.isrc");           //唯一标示
			$data['singer'] = I("param.singer");           //歌手
			$data['banner_img'] = I("param.banner_img");           //歌手
			$data['name'] = I("param.name");               //专辑名称
			$data['money'] = I("param.money");       //出售单价
			$data['inventory'] = I("param.inventory");       //发行量
			$data['release_time'] = strtotime(I("param.release_time"));       //发行时间
			$data['img'] = I("param.img");       //封面图
			$data['bottom_img'] = I("param.bottom_img");       //封底图
			$data['intro'] = I("param.intro");       //专辑介绍
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$edit_id_map['id'] = I('param.form_id');
			$result = $m_mall_content->where($edit_id_map)->save($data);
				#编辑专辑下歌曲
				$edit_id = I('param.edit_id');    #歌曲id
				$edit_name = I('param.edit_name');    #歌曲名称
				$edit_langues = I('param.edit_langues');    #歌曲语言
				$edit_lyrics = I('param.edit_lyrics');    #作词
				$edit_composes = I('param.edit_composes');    #作曲
				$edit_records = I('param.edit_records');    #录音
				$edit_mixings = I('param.edit_mixings');    #混音
				$edit_singers = I('param.edit_singers');    #演唱者
				$edit_producer = I('param.edit_producer');    #制作人
				$edit_producers = I('param.edit_producers');    #出品方
				$edit_music_lyrics = I('param.edit_music_lyrics');    #歌词
				
				
				foreach($edit_id as $i=>$v){
					$edit_song_map['id'] = $edit_id[$i];
					$edit_song_data['name'] = $edit_name[$i];
					$edit_song_data['langue'] = $edit_langues[$i];
					$edit_song_data['lyrics'] = $edit_lyrics[$i];
					$edit_song_data['compose'] = $edit_composes[$i];
					$edit_song_data['record'] = $edit_records[$i];
					$edit_song_data['mixing'] = $edit_records[$i];
					$edit_song_data['singer'] = $edit_singers[$i];
					$edit_song_data['producer'] = $edit_producer[$i];
					$edit_song_data['producers'] = $edit_producers[$i];
					$edit_song_data['value'] = $edit_music_lyrics[$i];
					#歌词  file上传
					$m_mall_content->where($edit_song_map)->save($edit_song_data);
				}
				
				
				
				#新增专辑下歌曲
				
				#添加流派风格
				add_style(2,$edit_id_map['id'],$style); 
				#获取对应歌曲个数
				$music_img_count = I('param.music_img_count');
				$xuanchuan_img_count = I('param.xuanchuan_img_count');
				$mp3_list = I('param.mp3');    #歌曲文件
				$music_name = I("param.music_name");   #歌曲名称 
				$langues = I('param.langues');    #语言
				$producers = I("param.producers");    #出品方 
				$producer = I("param.producer");    #制作人 
				$singers = I("param.singers");    #演唱者 
				$mixings = I("param.mixings");    #混音 
				$records = I("param.records");    #录音 
				$composes = I("param.composes");    #作曲 
				$lyrics = I("param.lyrics");    #作曲
				
				#歌词 music_lyrics
				$music_lyrics = $_FILES['music_lyrics'];
				foreach($music_lyrics as $i=>$v){
					foreach($music_lyrics[$i] as $ii=>$vv){
						$music_lyrics_list[$ii][$i] = $music_lyrics[$i][$ii];
					}
				}
			
				#歌词本底衬页图  foil_img
				$foil_img = $_FILES['foil_img'];
				
				foreach($foil_img as $i=>$v){
					foreach($foil_img[$i] as $ii=>$vv){
						$foil_img_list[$ii][$i] = $foil_img[$i][$ii];
					}
				}
				
				$uploadFiles = array();
				
				#歌词上传
				foreach($music_lyrics_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$geci_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$music_lyrics_list[$i]['name'],$uploadFiles[$i],$music_lyrics_list[$i]['size']);
				}
				
				#歌词本底衬页图  foil_img
				$uploadFiles = array();
				foreach($foil_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiles[] = $res['dest'];  
					}  
				}
				$uploadFiles=array_filter($uploadFiles);
				foreach($uploadFiles as $i=>$v){
					$img_name_list = explode("/",$uploadFiles[$i]);
					$count = count($img_name_list);
					$str_str = substr($uploadFiles[$i],1);
					$gecichenye_array[] = $str_str;
					#源文件与现文件记录
					upload_file_name($img_name_list[$count - 1],$foil_img_list[$i]['name'],$uploadFiles[$i],$foil_img_list[$i]['size']);
				}
				
				#宣传图  xuanchuan_img
				$xuanchuan_img = $_FILES['xuanchuan_img'];
				foreach($xuanchuan_img as $i=>$v){
					foreach($xuanchuan_img[$i] as $ii=>$vv){
						$xuanchuan_img_list[$ii][$i] = $xuanchuan_img[$i][$ii];
					}
				}
				
				$uploadFiless = array();
				foreach($xuanchuan_img_list as $fileInfo) {  
					$res = uploadFile($fileInfo);
					if(isset($res['dest'])) {  
						$uploadFiless[] = $res['dest'];  
					}  
				}
				
				$uploadFiless=array_filter($uploadFiless);
				foreach($uploadFiless as $i=>$v){
					$img_sname_list = explode("/",$uploadFiless[$i]);
					$count = count($img_sname_list);
					$str_strs = substr($uploadFiless[$i],1);
					$gecichenye_array[] = $str_strs;
					#源文件与现文件记录
					upload_file_name($img_sname_list[$count - 1],$xuanchuan_img_list[$i]['name'],$uploadFiless[$i],$xuanchuan_img_list[$i]['size']);
				}
				#添加该专辑下的歌曲
				$cc_count = 0;
				$cc_counts = 0;
				
				foreach($mp3_list as $gi=>$gv){
					$song_map['mp3'] = $mp3_list[$gi];
					$song_map['name'] = $music_name[$gi];
					$song_map['langue'] = $langues[$gi];
					$song_map['producers'] = $producers[$gi];
					$song_map['producer'] = $producer[$gi];
					$song_map['singer'] = $singers[$gi];
					$song_map['mixing'] = $mixings[$gi];
					$song_map['record'] = $records[$gi];
					$song_map['compose'] = $composes[$gi];
					$song_map['lyrics'] = $lyrics[$gi];
					
					if($geci_array[$gi]){
						$song_map['value'] = $geci_array[$gi];
					}
					$song_map['form_id'] = $edit_id_map['id'];
					$song_map['type'] = get_mall_model_conf('MALL_SONG');  //表示专辑下的歌曲
					$song_map['ip'] = get_client_ip();
					$song_map['status'] = 1;
					$geci_result = $m_mall_content->add($song_map);
					
					#添加试听歌曲
					$shiting_array = explode(".com/",$mp3_list[$gi]);
					$this->type_zhuanma_shiting(5,$geci_result,$shiting_array[1]);
					
					for ($x=0; $x<$music_img_count[$gi]; $x++) {
						mall_img(2,$geci_result,trim($uploadFiles[$cc_count],'.'));
						$cc_count ++;
					}
					
					for ($x=0; $x<$xuanchuan_img_count[$gi]; $x++) {
						mall_img(3,$geci_result,trim($uploadFiless[$cc_counts],'.'));
						$cc_counts ++;
					}
						
				}
			if($cc_count >0 or $result>0){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
			
				$this->success('编辑成功', U('Mall/Classify/all_Album'));
			
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
			
				$this->error('编辑失败');
			
			}
		
		}else{
			 #查询语言
			$langeue_list = getlangeues();
			#查询流派风格
			$style_list = gettypes();
			
			$map['id'] = I('param.id');
			$map['type'] = get_mall_model_conf('MALL_ALBUM');
			/* $map['status'] = array('in','1,2,4'); */
			$data = $m_mall_content->where($map)->find();
			
			#查询专辑下歌曲
			$f_map['form_id'] = $data['id'];
			$f_map['type'] = 17;    //专辑下歌曲
			$f_map['status'] = 1;  
			$f_list = $m_mall_content->where($f_map)->select();
			#查看歌曲名称
			foreach($f_list as $i=>$v){
				$url = $f_list[$i]['mp3'];
				$url_map['url'] = array("like","%$url%");
				$url_map['status'] = 1;
				$url_data = $m_common_upload->where($url_map)->find();
				#dump($url_map);
				$f_list[$i]['song_name'] = $url_data['original'];
				$f_list[$i]['song_size'] = getFilesize($url_data['size']);
				
				$value = $f_list[$i]['value'];
				$url_map['url'] = array("like","%$value%");
				$url_map['status'] = 1;
				$url_data = $m_common_upload->where($url_map)->find();
				$f_list[$i]['value_name'] = $url_data['original'];
				
				foreach($langeue_list as $ii=>$vv){
					if($langeue_list[$ii]['id'] == $f_list[$i]['langue']){
						$langeue_str[$i] .=  "<option selected='selected' value ='".$langeue_list[$ii]['id']."'>".$langeue_list[$ii]['name']."</option>";
					}else{
						$langeue_str[$i] .=  "<option value ='".$langeue_list[$ii]['id']."'>".$langeue_list[$ii]['name']."</option>";
					}
				}
				
			}
			#die;
			foreach($langeue_list as $i=>$v){
					$langeue_strs .= "<option value ='".$langeue_list[$i]['id']."'>".$langeue_list[$i]['name']."</option>";
				}
			#dump($langeue_str);die;
			$style_list = if_style($style_list,$data['style']);
			$this->assign("langeue_list",$langeue_list);
			$this->assign("langeue_str",$langeue_str);
			$this->assign("langeue_strs",$langeue_strs);
			$this->assign('data',$data);
			$this->assign('f_list',$f_list);
			$this->assign('style_list',$style_list);
			$this->display();
		}
	 }
	
	
	
	/**
	 *  专辑管理
	 */
    public function  Album(){
		
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		
		//判断是否搜索用户名
		$name = I('param.name');
		if($name){
			$map['name'] = array('like',"%$name%");
		}
		$this->assign('name',$name);
		
		//判断是否搜索状态
		$status = I('param.status');
		if($status){
			$map['status'] = $status;
			$this->assign('status',$status);
		}else{
			$map['status'] = array('in','1,2,3,4,5');
		}
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			//默认今天明天
			$begin_time=time();
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$map['type'] = get_mall_model_conf('MALL_ALBUM');
		$map['uid'] = getUID();
		$list = $m_mall_content->where($map)->order('time desc')->page($_GET['p'].',50')->select();
		#dump($map);die;
		$count      = $m_mall_content->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出 
		$this->assign('pages',$show);
		
		$status_list = getstatus();
		
		#type_zhuanma_shiting  转试听
		
		/* foreach($list as $i=>$v){
			$map_map['form_id'] = $list[$i]['id'];
			$data_data = $m_mall_content->where($map_map)->select();
			foreach($data_data as $ii=>$vv){
				$url_url = $data_data[$ii]['mp3'];
				
				$url_array = explode(".com/",$url_url);
				dump($url_array[1]);
				$this->type_zhuanma_shiting(5,$data_data[$ii]['id'],$url_array[1]);
				
			}
		}
		die; */
		//dump($status_list);die; 
		//赋值
		$this->assign('list',$list);
		$this->assign('status_list',$status_list);
		$this->display();
	}
	
	/**
	 * 菜单管理
	 */
    public function Manage(){
		common_public()->assign_page('分类管理');
		
		$m_mall_content = M('mall_content');
		
		//获得上级信息
		$fmap['id'] = I('param.form_id')?I('param.form_id'):0;
		$fmap['type'] = get_mall_model_conf('MALL_CLASSIFY');
		$fmap['status'] = 1;
		
		$data = $m_mall_content->where($fmap)->find();
		
		//获得菜单信息
		$map['form_id'] = $fmap['id'];
		$map['type'] = $fmap['type'];
		$map['status'] = 1;
		
		$list = $m_mall_content->where($map)->order('sort desc')->select();
		
		//赋值
		$this->assign('list',$list);
		$this->assign('data',$data);
		$this->assign('form_id',$fmap['id']);
		
		
		$this->display();
	}
	
	/**
	 * 新增菜单
	 */
	public function Create(){
		

		//判断是否是ajax请求
		if(IS_AJAX){

			$m_mall_content = M('mall_content');
			//获得数据
			$data = I();
			
			$data['value'] = I('param.value','','');
			$data['uid'] = getUID();
			$data['form_id'] =  I('param.form_id','','');
			$data['type'] = get_mall_model_conf('MALL_ALBUM');;
			$data['time'] = time();
			$data['ip'] = get_client_ip();
			$data['status'] = 1;
			
			$result = $m_mall_content->add($data);
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
			
			
				
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	/**
	 * 编辑菜单
	 */
	public function Edit(){
    
	
		//判断是否是ajax请求
		if(IS_AJAX){

			$m_mall_content = M('mall_content');
			$map['id'] = I('param.id');
			set_mall_draft($map['id']); //保存草稿
			
			$data = I('');
			unset($data['id']);
		
			$result = $m_mall_content->where($map)->save($data);
			
			//返回信息
			$info = $result?get_errcode(0):get_errcode(-1);
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);
	}
	
	/**
	 * 批量删除菜单
	 */
	public function Delete($id,$status=0){
		
	
		//判断是否是ajax请求
		if(IS_AJAX){
				
			$m_mall_content = M('mall_content');
		
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			
			if($id){
				
			
				$id = explode(',',$id); 
				
				
				foreach($id as $i=>$k){
					
					
					$map['id'] = $id[$i];
					$data['status'] = $status;
					
					$m_mall_content->where($map)->save($data);
					
				}
				
				//返回信息
				$info = get_errcode(0);
			
			}else{
				
				$info = get_errcode(10000001);
			}
			
	
		
		}
		
		//返回信息		
		$info = $info?$info:get_errcode(-2);

		$this->ajaxReturn($info);


	}
	
	/* 推荐专辑 */
	public function best_album(){
		
		$this->display();
	}
	
	/* 多图使用选择页面 */
    public function zip_log(){
	
		header("Content-type:text/html;charset=utf-8");	
		$m_mall_content_img = M("mall_content_img");    //多图选择表
		$m_common_upload = M("common_upload");    //上传记录表
		
		$type = I('param.type');
		$form_id = I('param.form_id');
		
		/* type为1封面  2歌词本地图 */
		$map['form_id'] = $form_id;
		$map['type'] = $type;
		$result = $m_mall_content_img->where($map)->order("sort desc")->select();
		if($result){
			foreach($result as $i=>$v){
				$url_name = explode("/",$result[$i]['url']);
				$url_count = count($url_name);
				$name = $url_name[$url_count-1];
				$img_map['title'] = array("like","%$name%");
				
				$img_name_array = $m_common_upload->where($img_map)->find();
			
				if($img_name_array){
					$list[$i]['original_name'] = $img_name_array['original'];
					$list[$i]['size'] = getFilesize($img_name_array['size']);
					$list[$i]['time'] = date("Y-m-d H:i",$img_name_array['time']);
					$list[$i]['url'] = $img_name_array['url'];
					$list[$i]['id'] = $result[$i]['id'];
					$list[$i]['sort'] = $result[$i]['sort'];
					$list[$i]['employ'] = $result[$i]['employ'];
				}else{
					$list[$i]['original_name'] = $list[$i]['img_name'];
					$list[$i]['size'] = "不详";
					$list[$i]['time'] = "不详";
					$list[$i]['url'] = $result[$i]['url'];
				}
			}
		}
		#dump($list);die;
		$this->assign("list",$list);
		$this->assign("form_id",$form_id);
		$this->assign("type",$type);
		$this->display();
	}
	
	public function zip_log_sort(){
		$m_mall_content_img = M("mall_content_img");
		
		$map['id'] = I("param.id");
		$data['sort'] = I('param.sort');
		$result = $m_mall_content_img->where($map)->save($data);
		if($result){
			$info = 1;
		}else{
			$info = 0;
		}
		$this->ajaxReturn($info);
	}
	
	/* 删除多图封面 */
	public function delete_file(){
		if(IS_AJAX){
			$m_mall_content_img = M("mall_content_img");    //多图选择表
			$id = I('param.id');
			if($id>0){
				$map['id'] = $id;
				$result = $m_mall_content_img->where($map)->delete();
			}
			
			if($result){
				$info = 1;
			}else{
				$info = 2;
			}
		}else{
			$info = 3;
		}
		$this->ajaxReturn($info);
		
	}
	
	/* 添加多图 */
	public function zip(){
		include_once 'upload.func.php';
		$m_mall_content_img = M("mall_content_img");    //多图选择表
		$form_id = I('param.form_id');
		$type = I('param.type');
		
		$files = getFiles(); 
		foreach($files as $fileInfo) {  
			$res = uploadFile($fileInfo);  
			if(isset($res['dest'])) {  
				$uploadFiles[] = $res['dest'];  
			}  
		} 
		$str = '';
		$uploadFiles=array_filter($uploadFiles);
		
		foreach($uploadFiles as $i=>$v){
			$img_name_list = explode("/",$uploadFiles[$i]);
			$count = count($img_name_list);
			$url = trim($uploadFiles[$i],'.');
			
			mall_img($type,$form_id,$url);
			upload_file_name($img_name_list[$count - 1],$files[$i]['name'],$uploadFiles[$i],$files[$i]['size']);
		}
		if($uploadFiles){
			$this->success("添加成功",U("Mall/Classify/zip_log/form_id/$form_id/type/$type"));
		}
	}
	
	
	/* 多图选择表 */
	public function employ(){
		$m_mall_content_img = M("mall_content_img");    //多图选择表
		
		$form_id = I("param.form_id");
		$type = I("param.type");
		$id = I("param.id");
		
		$map['form_id'] = $form_id;
		$map['type'] = $type;
		$data['employ'] = 0;
		$m_mall_content_img->where($map)->save($data);
		$save_map['id'] = $id;
		$save_data['employ'] = 1;
		$m_mall_content_img->where($save_map)->save($save_data);
		
		$this->ajaxReturn(1);
	}
	
	/* 专辑评论 */
	public function delete_music(){
		$m_mall_content = M("mall_content");
		$map['id'] = I('param.id');
		$map['uid'] = getUID();
		if($map['id']){
			$data['status'] = 0;
			$m_mall_content->where($map)->save($data);
		}
		$this->ajaxReturn(1);
		
		
	}
	
	/* 专辑评论 */
	public function album_comments(){
		$comments_id = I("param.comments_id");
		$list  = comments(3,$comments_id);
		
		$this->assign("list",$list);
		$this->display();
	}
	
	/* 活动评论 */
	public function Activity_comments(){
		$comments_id = I("param.comments_id");
		$list  = comments(1,$comments_id);
		
		$this->assign("list",$list);
		$this->display();
	}
	
	/* 单曲评论 */
	public function Song_comments(){
		
		$comments_id = I("param.comments_id");
		$list  = comments(2,$comments_id);
		
		$this->assign("list",$list);
		$this->display();
	}
	
	/* 删出歌曲 */
	public function delete_song(){
		$m_mall_content = M("mall_content");
		
		if(IS_POST){
			$map['id'] = I("param.id");
			$save_data['status'] = 0;
			$result  = $m_mall_content->where($map)->save($save_data);
			
		}
		$this->ajaxReturn($result);
		
	}
	
	public function comments_audit(){
		
		//判断是否是ajax请求
		if(IS_AJAX){
			$m_cms_content_comments = M("cms_content_comments");
		
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			if($id){
				$id = explode(',',$id); 
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					$data['status'] = $status;
					
					$m_cms_content_comments->where($map)->save($data);
					
				}
				//返回信息
				$info =1;
			
			}else{
				
				$info = -1;
			}
			
	
		
		}
		
		//返回信息		
		$info = $info?$info:-2;

		$this->ajaxReturn($info);
		
	}
	
	
	
	
}